package com.fairytask.ui.skillUnit
{
	import com.greensock.TweenLite;
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.ToolTips;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.group.ViewGroup;
	import com.fairytask.engine.components.text.Input;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.data.ViewObject;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.MoneyDefine;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.define.ViewDefine;
	import com.fairytask.engine.resource.StaticIni;
	import com.jzonl.managers.TipsManage;
	import com.jzonl.net.event.CustomToClientEvent;
	import com.jzonl.net.messages.CustomToClientEvent;
	import com.jzonl.net.messages.CustomToServerFlag;
	import com.jzonl.net.mgr.NetMgr;
	import com.fairytask.ui.MainSkillUI;
	import com.fairytask.ui.base.UnitUI;
	import com.fairytask.ui.effect.ChartEffect;
	import com.fairytask.ui.effect.MoneyEffect;
	import com.fairytask.ui.item.ChartItem;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	/**
	 * 命格UI 
	 * 命格配置文件 StatusChart.ini
	 * @author xujh
	 * 
	 */
	public class ChartUI extends UnitUI
	{
		private static var _self		:ChartUI;
		
		//UI显示
		public var moneyLab	:Label;		//消耗银两
		public var moneyIpt	:Input;		//消耗银两数值
		public var chartVG		:ViewGroup;	//16格命格
		public var getChartVG	:ViewGroup;	//获取的命格（5格）
		public var chartBuffVG	:ViewGroup;	//命格buff
		public var resetBtn	:Button;	//重置按钮
		public var openAllBtn	:Button;	//一键开启
		public var swallowAllBtn	:Button;	//一键吞噬
		//攻防体敏显示背景
		public var phyBg	:MovieClip;
		public var defBg	:MovieClip;
		public var stBg	:MovieClip;
		public var dexBg	:MovieClip;
		//点击菜单面板
		public var menuSP		:Sprite	= new Sprite();
		public var takeOnBtn	:Button;	//装备
		public var swallowBtn	:Button;	//吞噬
		public var takeOffBtn	:Button;	//卸下
		
		private var _curObjId	:Point;	//当前对象
		private var _curPos	:int;	//当前位置
		private var _isSwallow	:Boolean = false;	//是否是吞噬状态
		
		private var _startArrowMC	:Clip = new Clip();	//开始箭头
		private var _animeSpace	:Sprite = new Sprite();	//动画播放层
		private var _isCache		:Boolean = false;	//缓存数据，等播放完动画再加入数据
		private var _cacheData		:Array =[];
//		private var _cacheData		:ViewObject;
		private var _bindGetVGProp		:Array = [];	//5格绑定属性
		private var _bindBuffVGProp	:Array = [];	//buff绑定属性
		private var _isDead	:Boolean = false;
		//金钱播放动画用数据
		private var _isMulti	:Boolean = false;	//是否多个金钱
		private var _moneyPos	:int = -1;
		private var _moneyCount	:int = 0;		//用于检查是否全部播放完毕
		//银两特效
		private var _moneyEffect	:MoneyEffect;
		
		public static function getInstance():ChartUI
		{
			if (_self == null)
			{
				_self=new ChartUI;
			}
			return _self;
		}
		
		public function ChartUI()
		{
			super();
			init();
			initEvent();
			initBind();
		}
		
		private function init():void
		{
			//初始化选项菜单,不显示
			windowBG.addChild(menuSP);
			menuSP.visible = false;
			takeOffBtn.visible = false;
			//动画层
			windowBG.addChild(_animeSpace);
			
			//第一次打开面板给服务器发消息获取开始位置
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CLICK_LIFE_CHEQUER);
		}
		
		/**
		 * 初始化事件 
		 * 
		 */
		private function initEvent():void
		{
			resetBtn.addEventListener(MouseEvent.CLICK,onReset);
			openAllBtn.addEventListener(MouseEvent.CLICK,onOpenAll);
			swallowAllBtn.addEventListener(MouseEvent.CLICK,onSwallowAll);
			//点击16格
			chartVG.addItemsEvent(MouseEvent.CLICK,onChartClick);
			chartVG.addItemsEvent(MouseEvent.MOUSE_OVER,onChartOver);
			chartVG.addItemsEvent(MouseEvent.MOUSE_OUT,onOut);
			//5格点击，出菜单
			getChartVG.addItemsEvent(MouseEvent.CLICK,onShowMenu);
			getChartVG.addItemsEvent(MouseEvent.MOUSE_OVER,onOver);
			getChartVG.addItemsEvent(MouseEvent.MOUSE_OUT,onOut);
			//命格buff点击
			chartBuffVG.addItemsEvent(MouseEvent.CLICK,onShowOff);
			chartBuffVG.addItemsEvent(MouseEvent.MOUSE_OVER,onOver);
			chartBuffVG.addItemsEvent(MouseEvent.MOUSE_OUT,onOut);
			
			takeOnBtn.addEventListener(MouseEvent.CLICK,onTakeOn);
			takeOffBtn.addEventListener(MouseEvent.CLICK,onTakeOff);
			swallowBtn.addEventListener(MouseEvent.CLICK,onSwallow);
			GameStage.stage.addEventListener(MouseEvent.MOUSE_UP,hideBtn);
			//初始化命格显示
			model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_RESTING_CHART,resetChart);
			//格子状态信息
			model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_INFO_CHART,chartInfo);
			//发送奖励已领
			model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_GET_PRIZE,getChart);
			//发送命格状态
			model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_CHART_STATE,setChart);
			//发送开始位置
			model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_CHART_BEGIN_POS,beginPos);
		}
		
		/**
		 * 绑定视图 
		 * 
		 */
		private function initBind():void
		{
			bindManager.BindView(model.scene,ViewDefine.VIEWPORT_CHART_BOX,addGetChart,removeGetChart);
			bindManager.BindView(model.scene,ViewDefine.VIEWPORT_CHART_BUFFER_BOX,addChartBuff,removeChartBuff);
		}
		
		//================接收到数据处理==================
		/**
		 * 接受到初始化命格信息 
		 * @param evt
		 * 
		 */
		private function resetChart(evt:CustomToClientEvent):void
		{
			var pList	:Array	=	evt.pList;
			//显示开始位置
			startPos(pList.shift());
			//消耗银两
			moneyIpt.htmlStr = pList.shift();
			//先清空动画层
			clearSp(_animeSpace);
			//清空16格子
			clearVG(chartVG);
			//获取5个命格位置及物品，播放动画
			while(pList.length>1)
			{
				var res	:String = ResConfig.iconPath + StaticIni.getIniVar(pList.shift(),"Icon") + ResConfig.iconImg;
				var pos	:int = pList.shift();
				var chartItem	:ChartEffect = new ChartEffect(res,[chartVG.x + chartVG.width/2 -25,chartVG.y + chartVG.height/2 -25,chartVG.getItemByIndex(pos).x + chartVG.x + 3,chartVG.getItemByIndex(pos).y + chartVG.y + 3]);
				_animeSpace.addChild(chartItem);
			}
		}
		
		/**
		 * 发送命格状态 
		 * @param evt
		 * 
		 */
		private function setChart(evt:CustomToClientEvent):void
		{
			var pList	:Array	=	evt.pList;
			//消耗银两
			moneyIpt.htmlStr = pList.shift();
			while(pList.length>3)
			{
				var pos		:int = pList.shift();
				var direc	:int = pList.shift();
				var type	:int = pList.shift() + 1;
				var prize	:int = pList.shift();
				var tmpItem :ChartItem;
				if(null == chartVG.getItemByIndex(pos).getItem())
				{
					tmpItem = new ChartItem();
					chartVG.getItemByIndex(pos).addItem(tmpItem);
				}
				else
				{
					tmpItem = chartVG.getItemByIndex(pos).getItem() as ChartItem;
				}
				tmpItem.setData(type,direc,prize);
				//死亡命格处理
				if(_isDead && null!=chartVG.getItemByIndex(pos).filters && type==ChartItem.CHEQUER_CHART)
				{
					chartVG.getItemByIndex(pos).filters = null;
					tmpItem.addFilter();
				}
				//银两播放动画
				moneyAnime(pos,type,prize);
			}
			if(windowBG.contains(_startArrowMC))
			{
				_startArrowMC.visible = false;
			}
		}
		
		/**
		 * 送开始位置 
		 * @param event
		 * 
		 */
		private function beginPos(evt:CustomToClientEvent):void
		{
			startPos(evt.pList.shift());
			//消耗银两
			moneyIpt.htmlStr = evt.pList.shift();
		}
		
		/**
		 * 设置开始位置箭头
		 * @param pos
		 * 
		 */
		private function startPos(pos:int):void
		{
			if(pos<0)
			{
				return;
			}
			//是否包含箭头
			if(null == _startArrowMC.source)
			{
				//箭头
				_startArrowMC.source = ResConfig.pngResPath + "arrow_2.png";
				windowBG.addChild(_startArrowMC);
				_startArrowMC.mouseEnabled = false;
			}
			else
			{
				_startArrowMC.visible = true;
			}
			//设置箭头位置
			_startArrowMC.x = chartVG.getItemByIndex(pos).x + chartVG.x - 20;
			_startArrowMC.y = chartVG.getItemByIndex(pos).y + chartVG.y + 15;
		}
		
		/**
		 * 收到的格子消息显示处理
		 * @param evt
		 * //发送格子信息
		//参数： int result			格子状态
		 * {
	CHEQUER_EMPTY = 1,		//空白
	CHEQUER_MONEY = 2,		//银两
	CHEQUER_CHART = 3,		//命格
	CHEQUER_DEAD  = 4,		//死亡	
};
		//参数： int pos				位置
		//参数： int prize			奖励
		//参数： int nextMoney      下次点击消耗的银两
		//参数： int direc			方向
		 * {
	CHEQUER_UP,		//上
	CHEQUER_RIGHT,	//右
	CHEQUER_DOWN,	//下
	CHEQUER_LEFT,	//左
};
		 * 
		 */
		private function chartInfo(evt:CustomToClientEvent):void
		{
			var pList	:Array	=	evt.pList;
			var result	:int	=	pList.shift();
			var pos		:int	=	pList.shift();
			var prize	:int	=	pList.shift();
			//下次点击消耗的银两
			moneyIpt.htmlStr = pList.shift();
			var direc	:int	=	pList.shift();
			var tmpItem	:ChartItem;
			//添加对象
			if(null == chartVG.getItemByIndex(pos).getItem())
			{
				tmpItem = new ChartItem();
				chartVG.getItemByIndex(pos).addItem(tmpItem);
			}
			else
			{
				tmpItem = chartVG.getItemByIndex(pos).getItem() as ChartItem;
				tmpItem.clearItem();
			}
			tmpItem.setData(result,direc,prize);
			//银两播放动画
			moneyAnime(pos,result,prize);
			//起始位置箭头隐藏
			_startArrowMC.visible = false;
		}
		
		/**
		 * 获取命格 
		 * @param evt
		 * 
		 */
		private function getChart(evt:CustomToClientEvent):void
		{
			var pList		:Array	=	evt.pList;
			var type		:int	=	pList.shift();
			var pos			:int	=	pList.shift();
			//奖励
			if(type == 1)
			{
				if(null != chartVG.getItemByIndex(pos).getItem())
				{
					//有金钱
					if((chartVG.getItemByIndex(pos).getItem() as ChartItem).prize == 2)
					{
						//清除格子
						(chartVG.getItemByIndex(pos).getItem() as ChartItem).pickPrize();
					}
				}
			}
			//命格
			else
			{
				var targetPos	:int	=	pList.shift() - 1;
				//pos位置不为空
				if(null != chartVG.getItemByIndex(pos).getItem())
				{
					//有命格
					if((chartVG.getItemByIndex(pos).getItem() as ChartItem).chartID != 0)
					{
						var res	:String = ResConfig.iconPath + StaticIni.getIniVar((chartVG.getItemByIndex(pos).getItem() as ChartItem).chartID,"Icon") + ResConfig.iconImg;;
						var chartItem	:ChartEffect = new ChartEffect(res,[chartVG.getItemByIndex(pos).x + chartVG.x + 2,chartVG.getItemByIndex(pos).y + chartVG.y + 2,getChartVG.getItemByIndex(targetPos).x + getChartVG.x + 3,getChartVG.getItemByIndex(targetPos).y + getChartVG.y + 3],onPlayOver);
						_animeSpace.addChild(chartItem);
						//清除格子内的命格
						(chartVG.getItemByIndex(pos).getItem() as ChartItem).pickPrize();
						if(_isDead)
						{
							(chartVG.getItemByIndex(pos).getItem() as ChartItem).delFilter();
							chartVG.getItemByIndex(pos).filters = [Filter.GRAY];
						}
						_isCache = true;
					}
				}
			}
		}
		
		/**
		 * 播放金钱动画 
		 * 
		 */
		private function moneyAnime(pos:int,type:int,prize:int):void
		{
			if(type == ChartItem.CHEQUER_MONEY)
			{
				if(prize != 0)
				{
					_moneyEffect = new MoneyEffect(MoneyDefine.CAPITAL_TYPE_SILVER, MainSkillUI.getInstance().x + chartVG.getItemByIndex(pos).x + 310, MainSkillUI.getInstance().y + chartVG.getItemByIndex(pos).y + 110, onMoneyPlayOver);
					_moneyEffect.show();
					_moneyCount++;
					if(!_isMulti && _moneyPos != -1)
					{
						_isMulti = true;
					}
					_moneyPos = pos;
				}
			}
		}
		
		/**
		 * 动画播放完毕，添加数据
		 * 
		 */
		private function onPlayOver():void
		{
			if(_cacheData.length > 0)
			{
				addChartData(_cacheData.shift(),getChartVG);
			}
			//全部缓存完毕才重置状态
			if(_cacheData.length == 0)
			{
				_isCache = false;
			}
		}
		
		/**
		 * 金钱播放完毕 
		 * 
		 */
		private function onMoneyPlayOver():void
		{
			_moneyCount--;
			_moneyEffect.hide();
			//全部播放完毕
			if(_moneyCount == 0)
			{
				//给服务器发送消息
				if(_isMulti)
				{
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_PLAY_OVER,1);
				}
				else
				{
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_PLAY_OVER,2,_moneyPos);
				}
				_moneyPos = -1;
				_isMulti = false;
			}
		}
		//====================视图添加移除================
		/**
		 * 5格添加内容 
		 * @param key
		 * @param val
		 * @param data
		 * 
		 */
		private function addGetChart(key:String, val:ViewObject, data:Object):void
		{
			if(null == val.GetPropertiesEx("ConfigID"))
			{
				return;
			}
			//是否缓存数据
			if(_isCache)
			{
				_cacheData.push(val);
			}
			else
			{
				addChartData(val,getChartVG);
			}
			
		}
		
		/**
		 * 5格移除内容 
		 * @param key
		 * @param val
		 * @param data
		 * 
		 */
		private function removeGetChart(key:String, val:ViewObject, data:Object):void
		{
			delChartData(val,getChartVG);
		}
		
		/**
		 * 命格buff添加 
		 * @param key
		 * @param val
		 * @param data
		 * 
		 */
		private function addChartBuff(key:String, val:ViewObject, data:Object):void
		{
			if(null == val.GetPropertiesEx("ConfigID"))
			{
				return;
			}
			addChartData(val,chartBuffVG);
		}
		
		/**
		 * 命格buff移除
		 * @param key
		 * @param val
		 * @param data
		 * 
		 */
		private function removeChartBuff(key:String, val:ViewObject, data:Object):void
		{
			delChartData(val,chartBuffVG);
		}
		
		/**
		 * 往命格里面添加数据
		 * @param val 
		 * @param vg 
		 * 
		 */
		private function addChartData(val:ViewObject,vg:ViewGroup):void
		{
			var cfgId	:int = val.GetPropertiesEx("ConfigID");
			var pos		:int = val.GetProperties("Pos") - 1;
			var _clip	:Clip;
			if(null == vg.getItemByIndex(pos).getItem())
			{
				_clip =new Clip;
				_clip.x = 2;
				_clip.y = 3;
				vg.getItemByIndex(pos).addItem(_clip);
			}
			else
			{
				_clip = vg.getItemByIndex(pos).getItem() as Clip;
				_clip.clear();
				_clip.data = null;
			}
			_clip.data = new Object;
			_clip.source = ResConfig.iconPath + StaticIni.getIniVar(cfgId,"Icon") + ResConfig.iconImg;
			_clip.width = 50;
			_clip.height = 50;
			vg.getItemByIndex(pos).data = val;
			//绑定经验
			if(vg == chartBuffVG)
			{
				_bindBuffVGProp[pos] = [];
				_bindBuffVGProp[pos].push([val,"ConfigID",bindManager.BindPropInViewObj(model.scene.GetView(ViewDefine.VIEWPORT_CHART_BUFFER_BOX),val.ObjKey,"ConfigID",rConfigID,null,[_clip])]);
				_bindBuffVGProp[pos].push([val,"Exp",bindManager.BindPropInViewObj(model.scene.GetView(ViewDefine.VIEWPORT_CHART_BUFFER_BOX),val.ObjKey,"Exp",rNoeExp,null,[_clip])]);
			}
			else
			{
				_bindGetVGProp[pos] = [];
				_bindGetVGProp[pos].push([val,"ConfigID",bindManager.BindPropInViewObj(model.scene.GetView(ViewDefine.VIEWPORT_CHART_BOX),val.ObjKey,"ConfigID",rConfigID,null,[_clip])]);
				_bindGetVGProp[pos].push([val,"Exp",bindManager.BindPropInViewObj(model.scene.GetView(ViewDefine.VIEWPORT_CHART_BOX),val.ObjKey,"Exp",rNoeExp,null,[_clip])]);
			}
		}
		
		/**
		 * 更改configID 
		 * @param key
		 * @param val
		 * @param pList
		 * 
		 */
		private function rConfigID(key:String,val:int,pList:Array):void
		{
			var _clip	:Clip = pList[0] as Clip;
			//没有数据
			if(_clip.data[key])
			{
				chartEffect(_clip,val);
			}
			else
			{
				_clip.source = ResConfig.iconPath + StaticIni.getIniVar(val,"Icon") + ResConfig.iconImg;
			}
			_clip.data[key] = val;
		}
		
		/**
		 * 命格升级特效 
		 * 
		 */
		private function chartEffect(mc:Clip,val:int):void
		{
			//慢慢消失
			TweenLite.to(mc,1,{alpha:0,onComplete:onAlpha,onCompleteParams:[mc,val]});
		}
		
		/**
		 * 消失了出现新图标 
		 * @param mc
		 * @param val
		 * 
		 */
		private function onAlpha(mc:Clip,val:int):void
		{
			mc.source = ResConfig.iconPath + StaticIni.getIniVar(val,"Icon") + ResConfig.iconImg;
			//慢慢出现
			TweenLite.to(mc,1,{alpha:1});
		}
		
		/**
		 * 设置当前经验 
		 * @param key
		 * @param val
		 * @param pList
		 * 
		 */
		private function rNoeExp(key:String,val:int,pList:Array):void
		{
			var _clip	:Clip = pList[0] as Clip;
			_clip.data[key] = val;
		}
		
		/**
		 * 解绑数据 
		 * 
		 */
		private function unBindProp(arr:Array,pos:int):void
		{
			if((arr[pos] as Array).length > 0)
			{
				for each(var itemBind:Array in arr[pos])
				{
					bindManager.UnbindProp(itemBind.shift(),itemBind.shift(),itemBind.shift());
				}
				arr[pos] = [];
			}
		}
		
		/**
		 * 删除命格数据 
		 * @param val
		 * @param vg
		 * 
		 */
		private function delChartData(val:ViewObject,vg:ViewGroup):void
		{
			var pos		:int = val.GetProperties("Pos") - 1;
			if(null != vg.getItemByIndex(pos).data)
			{
				var _clip	:Clip = vg.getItemByIndex(pos).getItem() as Clip;
				_clip.clear();
				_clip.data = null;
				vg.getItemByIndex(pos).data = null;
				//解绑数据
				if(vg == chartBuffVG)
				{
					unBindProp(_bindBuffVGProp,pos);
				}
				else
				{
					unBindProp(_bindGetVGProp,pos);
				}
			}
		}
		
		//====================鼠标事件====================
		/**
		 * 重置按钮
		 * @param evt
		 * 
		 */
		private function onReset(evt:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_RESETING_CHEQUER);
		}
		
		/**
		 * 一键开启 
		 * @param evt
		 * 
		 */
		private function onOpenAll(evt:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_ALL);
		}
		
		/**
		 * 点击一键吞噬 
		 * @param evt
		 * 
		 */
		private function onSwallowAll(evt:MouseEvent):void
		{
			if(!_isCache)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SWALLOW_CHEQUER,2);
			}
		}
		
		/**
		 * 点击16格，抽命格 
		 * @param evt
		 * @param pos
		 * 
		 */
		private function onChartClick(evt:MouseEvent,pos:int):void
		{
			//点击开启命格
			if(null == chartVG.getItemByIndex(pos).getItem())
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CLICK_CHEQUER,pos);
			}
			else
			{
				var tmpItem	:ChartItem = chartVG.getItemByIndex(pos).getItem() as ChartItem;
				//收取命格
				if(tmpItem.prize == 1)
				{
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GET_PRIZE,tmpItem.prize,pos);
				}
			}
		}
		
		/**
		 * 点击显示装备吞噬菜单
		 * @param evt
		 * 
		 */
		private function onShowMenu(evt:MouseEvent,pos:int):void
		{
			if(null == getChartVG.getItemByIndex(pos).data || null == getChartVG.getItemByIndex(pos).getItem())
			{
				return;
			}
			//是否是吞噬，否则显示菜单
			if(_isSwallow)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SWALLOW_CHEQUER,1,_curObjId,(getChartVG.getItemByIndex(pos).data as ViewObject).objId);
				delChartFilter(getChartVG);
				_isSwallow = false;
			}
			else
			{
				menuSP.x = getChartVG.x + getChartVG.getItemByIndex(pos).x + 35;
				menuSP.y = getChartVG.y + getChartVG.getItemByIndex(pos).y + 35;
				menuSP.visible = true;
				_curObjId = (getChartVG.getItemByIndex(pos).data as ViewObject).objId;
			}
		}
		
		/**
		 * 隐藏小菜单 
		 * @param evt
		 * 
		 */
		private function hideBtn(evt:MouseEvent):void
		{
			menuSP.visible = false;
			takeOffBtn.visible = false;
			//吞噬延时
			if(_isSwallow)
			{
				var timer:Timer = new Timer(100,1);
				timer.addEventListener(TimerEvent.TIMER, checkClick);
				timer.start();
			}
//			_curObjId = null;
		}
		
		/**
		 * 检查点击状态 
		 * @param evt
		 * 
		 */
		private function checkClick(evt:TimerEvent):void
		{
			if(_isSwallow)
			{
				delChartFilter(getChartVG);
				_isSwallow = false;
			}
		}
		/**
		 * 卸载 
		 * @param evt
		 * @param pos
		 * 
		 */
		private function onShowOff(evt:MouseEvent,pos:int):void
		{
			if(null == chartBuffVG.getItemByIndex(pos).data || null == chartBuffVG.getItemByIndex(pos).getItem())
			{
				return;
			}
			takeOffBtn.x = chartBuffVG.x + chartBuffVG.getItemByIndex(pos).x + 35;
			takeOffBtn.y = chartBuffVG.y + chartBuffVG.getItemByIndex(pos).y + 35;
			takeOffBtn.visible = true;
			_curObjId = (chartBuffVG.getItemByIndex(pos).data as ViewObject).objId;
		}
		
		/**
		 * 16格有命格显示tips 
		 * @param evt
		 * @param pos
		 * 
		 */
		private function onChartOver(evt:MouseEvent,pos:int):void
		{
			if(null != (evt.currentTarget as BaseItem).getItem())
			{
				if(((evt.currentTarget as BaseItem).getItem() as ChartItem).chartID != 0)
				{
					TipsManage.showChartTips(((evt.currentTarget as BaseItem).getItem() as ChartItem).chartID,0);
				}
			}
		}
		
		/**
		 * 显示tips 
		 * @param evt
		 * @param pos
		 * 
		 */
		private function onOver(evt:MouseEvent,pos:int):void
		{
			var tmpItem	:BaseItem = evt.currentTarget as BaseItem;
			if(null == tmpItem.data || null == tmpItem.getItem())
			{
				return;
			}
			var cfgID	:int = (tmpItem.getItem() as Clip).data["ConfigID"];
			if(cfgID != 0)
			{
				TipsManage.showChartTips(cfgID,(tmpItem.getItem() as Clip).data["Exp"]);
			}
		}
		
		/**
		 * 隐藏tips 
		 * @param evt
		 * @param pos
		 * 
		 */
		private function onOut(evt:MouseEvent,pos:int):void
		{
			ToolTips.hide();
		}
		
		/**
		 * 点击装备
		 * @param evt
		 * 
		 */
		private function onTakeOn(evt:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_EQUIP_CHEQUER,_curObjId);
			_curObjId = null;
		}
		
		/**
		 * 点击吞噬 
		 * @param evt
		 * 
		 */
		private function onSwallow(evt:MouseEvent):void
		{
			_isSwallow = true;
			//高亮
			addChartFilter();
		}
		
		/**
		 * 点击卸载
		 * @param evt
		 * 
		 */
		private function onTakeOff(evt:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REMOVE_CHART,_curObjId);
			_curObjId = null;
		}
		//====================鼠标事件结束====================
		/**
		 * 设置是否死亡 
		 * 
		 */
		public function set isDead(val:Boolean):void
		{
			_isDead = val;
			//死亡所有加滤镜
			if(_isDead)
			{
				addChartDead();
			}
			else
			{
				delChartFilter(chartVG);
			}
		}
		
		/**
		 * 死亡全部变灰 
		 * 
		 */
		private function addChartDead():void
		{
			chartVG.getItemForEach(function (baseItem:BaseItem):void
			{
				if(baseItem.getItem() is ChartItem)
				{
					var tmpItem:ChartItem=baseItem.getItem() as ChartItem;
					//是命格
					if(tmpItem.prize == 1)
					{
						tmpItem.addFilter();
					}
					else
					{
						baseItem.filters = [Filter.GRAY];
					}
				}
				else
				{
					baseItem.filters = [Filter.GRAY];
				}
			});
		}
		
		/**
		 * 添加命格高亮 
		 * 
		 */
		private function addChartFilter():void
		{
			getChartVG.getItemForEach(function (baseItem:BaseItem):void
			{
				//不为空
				if(null != baseItem.data)
				{
					if(baseItem.data.CheckProperties("Pos"))
					{
						baseItem.filters = [Filter.YELLOW_INNER];
					}
				}
			});
		}
		
		/**
		 * 清除命格滤镜
		 * 
		 */
		private function delChartFilter(vg:ViewGroup):void
		{
			vg.getItemForEach(function (baseItem:BaseItem):void
			{
				if(null != baseItem.data)
				{
					baseItem.filters = null;
				}
			});
		}
		
		/**
		 * 清空层 
		 * @param sp
		 * 
		 */
		private function clearSp(sp:Sprite):void
		{
			while(sp.numChildren>0)
			{
				sp.removeChildAt(0);
			}
		}
		
		/**
		 * 清空容器
		 * @param val
		 * 
		 */
		private function clearVG(val:ViewGroup):void
		{
			val.getItemForEach(function (baseItem:BaseItem):void
			{
				baseItem.clear();
			});
			isDead = false;
		}
	}
}